package hu.elte.inf.holiuml.fileutil;

import java.io.IOException;

import javax.swing.JFrame;

import hu.elte.inf.holiuml.model.Document;

/**
 * File utilities, like open and save.
 * In memory Document <--> { XML, binary, RDB, FastInfoSet, text, ... }  
 * 
 * @author Jozsef Sipos
 *
 */
public interface PersistenceService {

	/**
	 * This method is called when the user wants to open a
	 * previously saved Simple HoliUML Document File. It will open
	 * a JFileChooser dialog, in which the user can select the file
	 * to be loaded.
	 * 
	 * @return	The Document object created from the XML stored
	 *          in the selected file, or null, if the user
	 *          has changed his or her mind and pressed Cancel.
	 *          
	 * @throws	IOException Cannot read file, wrong file format, etc...
	 */
	Document open(JFrame mainFrame) throws IOException;
	
	/**
	 * Save the passed model to a file. If the model was opened from file,
	 * then it will be saved to the same file. Otherwise a JFileChooser will
	 * pop up, and the user can select the file to be created. 
	 * @see saveModelAs(Document model)
	 * 
	 * @param document	The model to be saved
	 * @throws IOException	Anything could occur :)
	 */
	void save(Document document, JFrame mainFrame) throws IOException;
	
	/**
	 * A JFileChooser will pop up, and the model is saved to the file
	 * the user chooses. After calling this method, the model will be
	 * assigned to the newly created file, so subsequent calls of the
	 * <code>saveModel(Document)</code> method will save the model to this
	 * location.
	 * 
	 * @param document	The model to be saved
	 * @throws IOException	Cannot create file there, or something
	 */
	void saveAs(Document document, JFrame mainFrame) throws IOException;
	
}